package org.aeon.gamechatnest.mapper;

import org.aeon.gamechatnest.pojo.UserServer;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Liys
 * @description 针对表【user_server(服务器表)】的数据库操作Mapper
 * @createDate 2024-05-09 09:25:50
 * @Entity org.aeon.gamechatnest.pojo.UserServerService
 */
@Mapper
public interface UserServerMapper {
    /**
     * 新增用户服务器
     *
     * @param userServer
     * @return
     */
    int add(UserServer userServer);

    /**
     * 通过服务器id删除服务器
     *
     * @param serverId
     * @return
     */
    @Delete("delete from user_server where server_id=#{serverId}")
    int deleteById(Long serverId);

    /**
     * 通过服务器id修改服务器
     *
     * @param userServer
     * @return
     */
    int updateById(UserServer userServer);

    /**
     * 通过服务器名称模糊查询服务器
     *
     * @param name
     * @return
     */
    List<UserServer> getByName(@Param("name") String name);

    /**
     * 通过服务器id查询服务器
     *
     * @param serverId
     * @return
     */
    @Select("select server_id, user_id, name, head_image, introduce, create_time from user_server where server_id=#{serverId}")
    UserServer getById(@Param("serverId") Long serverId);

    /**
     * 查询存在
     *
     * @param serverId
     * @return
     */
    @Select("select COUNT(server_id) from user_server where server_id=#{serverId}")
    boolean isExist(@Param("serverId") Long serverId);

    /**
     * 服务器存在且为用户创建
     *
     * @param serverId
     * @param userId
     * @return
     */
    @Select("select COUNT(server_id) from user_server where server_id=#{serverId} and user_id=#{userId}")
    int isExistByUserId(@Param("serverId") Long serverId, @Param("userId") Long userId);

    /**
     * 用户加入的服务器
     * @param userId
     * @return
     */
    List<UserServer> getByUserId(@Param("userId") Long userId);
}




